﻿using IM.Easy.Core.AppContext;
using IM.Easy.Core.Cache;
using IM.Easy.Core.Configuration;
using IM.Easy.Core.Log;
using IM.Easy.Core.Middleware;
using SqlSugar;
using System.Configuration;

namespace IM.Easy.Api.Extensions
{
    public static class IHostBuilderExtensions
    {
        /// <summary>
        /// 核心插件
        /// </summary>
        /// <param name="host"></param>
        /// <returns></returns>
        public static IHostApplicationBuilder PresetAppCore(this IHostApplicationBuilder host)
        {

            var configuration = host.Configuration;
            ConfigManager.Initialize(host);
            ConfigManager.Configure(configuration);

            host.Services.AddTransient<IExceptionLogger, VirtualExceptionLogger>();
            host.Services.AddTransient<IExceptionLogger, ExceptionLogger>();
            host.Services.AddTransient<ImExceptionHandlingMiddleware>();
            //注入当前系统用户
            host.Services.AddTransient<IUserContext, UserContext>();
            return host;
        }
    }
}
